package org.westboy.common.base;

import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.input.MouseEvent;
import org.westboy.App;


/**
 * Description:
 *
 * @author Jin
 * @create 2017-12-26
 **/
public abstract class BaseController {

    private double lastxDistance;

    private double lastyDistance;

    protected String [] ws = {
            "醉卧沙场君莫笑，古来征战几人回"
            ,"醉卧美人漆，醒掌杀人权",
            "用舍由人，行藏在我"
            ,"一门七进士，父子三探花",
            "匈奴未灭，何以为家",
            "我本楚狂人，凤歌笑孔丘",
            "痛饮狂歌空度日,飞扬跋扈为谁雄"
    };

    @FXML
    private void mouseDraggedAction(final MouseEvent event){
        App.getStage().setX(event.getScreenX()-lastxDistance);
        App.getStage().setY(event.getScreenY()-lastyDistance);
    }


    @FXML
    private  void mousePressedAction(final MouseEvent event){
        lastxDistance = event.getScreenX()-App.getStage().getX();
        lastyDistance = event.getScreenY()-App.getStage().getY();
    }

    protected void showErrorAlert(String msg){
       Platform.runLater(()->{
                Alert alert = new Alert(Alert.AlertType.INFORMATION, msg);
                alert.initOwner(App.getStage());
                alert.showAndWait();
       });
    }

    @FXML
    private void exitAction(){
       App.addSystemTrayIconAndHide();
    }


    @FXML
    protected abstract void initialize();

}
